﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace Telmex
{
    /// <summary>
    /// The configuration section for the Telmex API.
    /// </summary>
    public class TelmexConfigurationSection : ConfigurationSection
    {
        /// <summary>
        /// The username of the API.
        /// </summary>
        [ConfigurationProperty("apiUsername")]
        public string ApiUsername
        {
            get { return (string)this["apiUsername"]; }
            set { this["apiUsername"] = value; }
        }

        /// <summary>
        /// The secret (password) for the configured username.
        /// </summary>
        [ConfigurationProperty("apiSecret")]
        public string ApiSecret
        {
            get { return (string)this["apiSecret"]; }
            set { this["apiSecret"] = value; }
        }

        /// <summary>
        /// The Telmex ID for the responsible of the conferences.
        /// </summary>
        [ConfigurationProperty("defaultResponsibleId")]
        public string DefaultResponsibleId
        {
            get { return (string)this["defaultResponsibleId"]; }
            set { this["defaultResponsibleId"] = value; }
        }

        /// <summary>
        /// The email of the responsible of the conferences.
        /// </summary>
        [ConfigurationProperty("defaultResponsibleEmail")]
        public string DefaultResponsibleEmail
        {
            get { return (string)this["defaultResponsibleEmail"]; }
            set { this["defaultResponsibleEmail"] = value; }
        }

        /// <summary>
        /// Checks if all the required settings are stored in configuration.
        /// </summary>
        /// <returns></returns>
        public static bool IsConfigured()
        {
            // Get the configuration section
            var section = ConfigurationManager.GetSection("telmex") as TelmexConfigurationSection;

            // Check for credentials and defaults
            return  !String.IsNullOrWhiteSpace(section.ApiUsername) &&
                    !String.IsNullOrWhiteSpace(section.ApiSecret) &&
                    !String.IsNullOrWhiteSpace(section.DefaultResponsibleId) &&
                    !String.IsNullOrWhiteSpace(section.DefaultResponsibleEmail);
        }
    }
}
